import React from "react";
import DatePicker from "../../DatePicker";
import { getTimestamp } from "../utils";
import { useErrmsgStyles } from "./styles";

export default function DatePickerComponent({
  value,
  picker,
  errmsg,
  disabled,
  onChange,
}: {
  value?: string | number;
  picker: "date" | "datetime";
  errmsg?: string;
  disabled?: boolean;
  onChange: (v?: number) => void;
}) {
  const classes = useErrmsgStyles();
  return (
    <>
      <DatePicker
        picker={picker}
        disabled={disabled}
        onChange={(v) => onChange(v?.valueOf())}
        defaultValue={getTimestamp(value)}
      />
      {errmsg && <div className={classes.errmsg}>{errmsg}</div>}
    </>
  );
}
